package sample;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import javafx.animation.FadeTransition;
import javafx.animation.PathTransition;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.Observable;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.concurrent.WorkerStateEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import  javafx.scene.control.Label;
import  javafx.scene.control.*;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Paint;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.Rectangle;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;

import okhttp3.*;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;


public class Controller {
    private static int person_flag=0;
    private static int flag=0;
    private static String uid,user,sex,place,ctime,name,class_list,grade,xf_detials,xq,fdy;
    private static String fid;
    @FXML
    private ImageView person_image;
    @FXML
    public Label greeting_user;
    @FXML
    private Label main_stu_person;
    @FXML
    private ImageView main_stu_image_person;
    @FXML
    private Label greeting_cancle;
    @FXML
    private Label tip;
    @FXML
    private Button Login;
    @FXML
    private ImageView min;
    @FXML
    private ImageView cancle;
    @FXML
    private TextField username;
    @FXML
    private PasswordField password;
    @FXML
    private Label label_cancle;
    @FXML
    private TableColumn<grade_info,String> kcmc;
    @FXML
    private TableColumn<grade_info,String> teacher;
    @FXML
    private TableColumn<grade_info,String>xf;
    @FXML
    private TableColumn<grade_info,String>cj;
    @FXML
    private TableView<grade_info> grade_list;
    @FXML
    private Label main_cancle;
    @FXML
    private Label main_min;
    @FXML
    private AnchorPane main_more_container;
    @FXML
    private Label main_more_login;
    @FXML
    private Label main_more_cancle;
    @FXML
    private Label xf_average;
    @FXML
    private Label xf_sum;
    @FXML
    private Label class_range;
    @FXML
    private Label class_school_range;
    @FXML
    private Label main_stu_xq;
    @FXML
    private ProgressIndicator xf_progress;
    @FXML
    private Label main_stu_label_main;
    @FXML
    private ImageView main_stu_image_main;
    @FXML
    private Label main_stu_label_thing;
    @FXML
    private Pane main_stu_pane;
    @FXML
    private Label main_stu_title;
    @FXML
    private AnchorPane main_stu_person_an;
    @FXML
    private ImageView main_stu_image_thing;
    public ObservableList<grade_info> data= FXCollections.observableArrayList();
    @FXML
    private Pane person_pane;
    @FXML
    private Pane person_pane1;
    @FXML
    private Pane person_pane11;
    @FXML
    private Pane person_pane111;
    @FXML
    private Pane person_pane1111;

    @FXML
    private ImageView person_1_image;
    @FXML
    private ImageView person_2_image;
    @FXML
    private ImageView person_3_image;
    @FXML
    private ImageView person_4_image;
    @FXML
    private ImageView person_5_image;
    @FXML
    private AnchorPane person_message_an;
    @FXML
    private ImageView bg;
    @FXML
    private Label person_name_1;
    @FXML
    private Label person_sign_1;
    @FXML
    private Label person_username_1;
    @FXML
    private Label person_name2_1;
    @FXML
    private Label person_now_place_1;
    @FXML
    private TextField person_page_fdy;
    @FXML
    private Label person_pre_place_1;
    @FXML
    private Label person_email_1;
    @FXML
    private Label person_xy_1;
    @FXML
    private Label person_bj_1;
    @FXML
    private Label person_fdy_1;
    @FXML
    private ImageView bz_image;
    @FXML
    private TextField bz_text;
    @FXML
    private Button person_cancle;
    @FXML
    private ImageView person_page_image;
    @FXML
    private Label person_page_name_label;
    @FXML
    private Label person_page_sign_label;
    @FXML
    private TextField person_page_name_text;
    @FXML
    private SplitMenuButton person_page_sex;
    @FXML
    private TextField person_page_birthday;
    @FXML
    private SplitMenuButton person_page_xx;
    @FXML
    private TextField person_page_sign_text;
    @FXML
    private SplitMenuButton person_page_id;
    @FXML
    private TextField person_page_xy;
    @FXML
    private TextField person_page_bj;
    @FXML
    private TextField person_page_now_place;
    @FXML
    private TextField person_page_pre_place;
    @FXML
    private TextField person_page_phone;
    @FXML
    private TextField person_page_email;
    @FXML
    private TextArea person_page_introuduce;
    @FXML
    private ImageView greeting_image;
    @FXML
    private Button save;
    @FXML
    private Button cancle_person;
    @FXML
    private void bz_click(){
        bz_image.setVisible(false);
        bz_text.setVisible(true);
    }
    @FXML
    private void person_page_cancle(){
        Stage First_stage=(Stage)person_cancle.getScene().getWindow();

        First_stage.close();
    }
    @FXML
    private void main_click(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#F8DA82"),null, javafx.geometry.Insets.EMPTY);
        main_stu_person.setBackground(null);
        Rectangle rectangle=new Rectangle(main_stu_label_main.prefWidth(-1),main_stu_label_main.prefHeight(-1));
        rectangle.setArcWidth(16);
        rectangle.setArcHeight(16);
        main_stu_label_main.setClip(rectangle);
        File file=new File("src/res/fun_image/main_end.png");
        String string=file.toURI().toString();
        Image image=new Image(string);
        main_stu_image_main.setImage(image);
        main_stu_label_main.setBackground(new Background(backgroundFill));
        main_stu_image_person.setImage(new Image(new File("src/res/fun_image/person_group_start.png").toURI().toString()));
        main_stu_label_thing.setBackground(null);
        main_stu_image_thing.setImage(new Image(new File("src/res/fun_image/agenda_start.png").toURI().toString()));
        main_stu_pane.setVisible(true);
        main_stu_title.setVisible(true);
        grade_list.setVisible(true);
        main_stu_person_an.setVisible(false);
        bg.setVisible(false);
    }
    @FXML
    private void save_button(){
        save.setStyle("-fx-background-color:#2887BA;-fx-background-radius:8px;");
    }
    @FXML
    private void save_button_exit(){
        save.setStyle("-fx-background-color:#73C5E5;-fx-background-radius:8px;");
    }
    @FXML
    private void cancle_button(){
        person_cancle.setStyle("-fx-background-color:#C72B04;-fx-background-radius:8px;");
    }
    @FXML
    private void cancle_button_exit(){
        person_cancle.setStyle("-fx-background-color:#EC4B58;-fx-background-radius:8px;");
    }
    @FXML
    private void login_button_color(){
        Login.setStyle("-fx-background-color:linear-gradient(to right,#3892B3,#66C3F2);-fx-background-radius:16px;");
    }
    @FXML
    private void login_button_exit(){
        Login.setStyle("-fx-background-color:linear-gradient(to right,#66C3F2,#3892B3);-fx-background-radius:16px;");
    }
    @FXML
    private void person_page_init(){
            if(person_flag==0){
                String url_cmmon="http://127.0.0.1:5000/get_person_message";
                OkHttpClient client1=new OkHttpClient();
                JSONObject json=new JSONObject();
                MediaType JSON=MediaType.parse("application/json;charset=utf-8");
                json.put("username",user);
                RequestBody body=RequestBody.create(JSON,String.valueOf(json));
                Request request1=new Request.Builder()
                        .url(url_cmmon)
                        .addHeader("Content-Type", "application/json")
                        .post(body)
                        .build();
                Response response1= null;
                try {
                    response1 = client1.newCall(request1).execute();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String data1= null;
                try {
                    data1 = response1.body().string();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                JSONObject object1=(JSONObject)JSONObject.parse(data1);
                Rectangle rectangle=new Rectangle(person_page_image.prefWidth(-1),person_page_image.prefHeight(-1));
                rectangle.setArcWidth(100);
                rectangle.setArcHeight(100);
                person_page_image.setClip(rectangle);
                person_page_name_label.setText(object1.getString("remark"));
                person_page_sign_label.setText(object1.getString("sign"));
                person_page_name_text.setText(object1.getString("remark"));
                if(sex.compareTo("0.0")==0){
                    person_page_sex.setText("男");
                }else person_page_sex.setText("女");
                person_page_birthday.setText(object1.getString("birthday"));
                if(object1.getString("xx").compareTo("1.0")==0){
                    person_page_xx.setText("A型");
                }else if(object1.getString("xx").compareTo("2.0")==0){
                    person_page_xx.setText("B型");
                }else if(object1.getString("xx").compareTo("3.0")==0){
                    person_page_xx.setText("O型");
                }else if(object1.getString("xx").compareTo("4.0")==0){
                    person_page_xx.setText("AB型");
                }else{
                    person_page_xx.setText("其他血型");
                }
                person_page_sign_text.setText(object1.getString("sign"));
                person_page_fdy.setText(fdy);
                person_page_xy.setText(object1.getString("xy"));
                person_page_bj.setText(object1.getString("bj"));
                person_page_now_place.setText(object1.getString("now_place"));
                person_page_pre_place.setText(object1.getString("pre_place"));
                person_page_phone.setText(object1.getString("phone"));
                person_page_email.setText(object1.getString("email"));
                person_page_introuduce.setText(object1.getString("introuduce"));
                person_flag=1;
            }

    }
    @FXML
    private void update_personage() throws IOException {
        String url_cmmon="http://127.0.0.1:5000/update_person_m";
        OkHttpClient client1=new OkHttpClient();
        JSONObject json=new JSONObject();
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        json.put("username","admin");
        json.put("remark",person_page_name_text.getText());
        json.put("birthday",person_page_birthday.getText());
        json.put("xx",person_page_xx.getText());
        json.put("sign",person_page_sign_text.getText());
        json.put("now_place",person_page_now_place.getText());
        json.put("bj",person_page_bj.getText());
        json.put("pre_place",person_page_pre_place.getText());
        json.put("fdy",person_page_fdy.getText());
        json.put("email",person_page_email.getText());
        json.put("phone",person_page_phone.getText());
        json.put("introduce",person_page_introuduce.getText());
        json.put("xy",person_page_xy.getText());
        RequestBody body=RequestBody.create(JSON,String.valueOf(json));
        Request request1=new Request.Builder()
                .url(url_cmmon)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response1=client1.newCall(request1).execute();
        String data1=response1.body().string();
        System.out.println(data1);
        if(data1.equals("0")){
            Alert alert=new Alert(Alert.AlertType.INFORMATION);
            alert.titleProperty().set("提示");
            alert.headerTextProperty().set("网络出现问题请稍后提交");
            alert.showAndWait();
        }else{
            Alert alert=new Alert(Alert.AlertType.INFORMATION);
            alert.titleProperty().set("提示");
            alert.headerTextProperty().set("提交成功");
            alert.showAndWait();
        }
    }

    @FXML
    private void show_person_page() throws IOException {
        Stage stage1=new Stage();
        Parent root1=FXMLLoader.load(getClass().getResource("person_page.fxml"));
        stage1.setScene(new Scene(root1));
        stage1.initStyle(StageStyle.UNDECORATED);
        stage1.show();

    }
    @FXML
    private void delete_fid() throws IOException {
        if(fid.compareTo("优酸乳")==0){
            person_pane1111.setVisible(false);
        }else if(fid.compareTo("王老吉")==0){
            person_pane111.setVisible(false);
        }else if(fid.compareTo("农夫山泉")==0){
            person_pane11.setVisible(false);
        }else if(fid.compareTo("lgt153")==0){
            person_pane1.setVisible(false);
        }
        String url_cmmon="http://127.0.0.1:5000/delete_friend";
        OkHttpClient client1=new OkHttpClient();
        JSONObject json=new JSONObject();
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        json.put("uid",fid);
        RequestBody body=RequestBody.create(JSON,String.valueOf(json));
        Request request1=new Request.Builder()
                .url(url_cmmon)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response1=client1.newCall(request1).execute();
        String data1=response1.body().string();
        System.out.println(data1);
        if(data1.equals("0")){
            Alert alert=new Alert(Alert.AlertType.INFORMATION);
            alert.titleProperty().set("提示");
            alert.headerTextProperty().set("网络出现问题请稍后提交");
            alert.showAndWait();
        }
    }
    @FXML
    private void bz_drag() throws IOException {
        bz_image.setVisible(true);
        bz_text.setVisible(false);
        String url_cmmon="http://127.0.0.1:5000/update_person_message";
        OkHttpClient client1=new OkHttpClient();
        JSONObject json=new JSONObject();
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        json.put("bz",bz_text.getText());
        json.put("username",user);
        json.put("fid",fid);
        RequestBody body=RequestBody.create(JSON,String.valueOf(json));
        Request request1=new Request.Builder()
                .url(url_cmmon)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response1=client1.newCall(request1).execute();
        String data1=response1.body().string();
        System.out.println(data1);
        if(data1.equals("0")){
            Alert alert=new Alert(Alert.AlertType.INFORMATION);
            alert.titleProperty().set("提示");
            alert.headerTextProperty().set("网络出现问题请稍后提交");
            alert.showAndWait();
        }
    }
    @FXML
    private void show_person_message4() throws IOException {
        String url_cmmon="http://127.0.0.1:5000/get_person_message";

        OkHttpClient client1=new OkHttpClient();
        JSONObject json=new JSONObject();
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        json.put("username","优酸乳");
        RequestBody body=RequestBody.create(JSON,String.valueOf(json));
        Request request1=new Request.Builder()
                .url(url_cmmon)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response1=client1.newCall(request1).execute();
        String data1=response1.body().string();
        JSONObject object1=(JSONObject)JSONObject.parse(data1);
        fid=object1.getString("username");
        person_name_1.setText(object1.getString("bz"));
        String image_url="src/res/image/"+object1.getString("image");
        person_image.setImage(new Image(new File(image_url).toURI().toString()));
        person_username_1.setText(fid);
        person_sign_1.setText(object1.getString("sign"));
        person_name2_1.setText(object1.getString("remark"));
        person_now_place_1.setText(object1.getString("now_place"));
        person_pre_place_1.setText(object1.getString("pre_place"));
        person_email_1.setText(object1.getString("email"));
        person_xy_1.setText(object1.getString("xy"));
        person_bj_1.setText(object1.getString("bj"));
        person_fdy_1.setText(object1.getString("fdy"));
        person_message_an.setVisible(true);
        bg.setVisible(false);
    }
    @FXML
    private void show_person_message3() throws IOException {
        String url_cmmon="http://127.0.0.1:5000/get_person_message";
        OkHttpClient client1=new OkHttpClient();
        JSONObject json=new JSONObject();
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        json.put("username","王老吉");
        RequestBody body=RequestBody.create(JSON,String.valueOf(json));
        Request request1=new Request.Builder()
                .url(url_cmmon)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response1=client1.newCall(request1).execute();
        String data1=response1.body().string();
        JSONObject object1=(JSONObject)JSONObject.parse(data1);
        fid=object1.getString("username");
        person_name_1.setText(object1.getString("bz"));
        person_username_1.setText(fid);
        person_sign_1.setText(object1.getString("sign"));
        String image_url="src/res/image/"+object1.getString("image");
        person_image.setImage(new Image(new File(image_url).toURI().toString()));
        person_name2_1.setText(object1.getString("remark"));
        person_now_place_1.setText(object1.getString("now_place"));
        person_pre_place_1.setText(object1.getString("pre_place"));
        person_email_1.setText(object1.getString("email"));
        person_xy_1.setText(object1.getString("xy"));
        person_bj_1.setText(object1.getString("bj"));
        person_fdy_1.setText(object1.getString("fdy"));
        person_message_an.setVisible(true);
        bg.setVisible(false);
    }
    @FXML
    private void show_person_message2() throws IOException {
        String url_cmmon="http://127.0.0.1:5000/get_person_message";
        OkHttpClient client1=new OkHttpClient();
        JSONObject json=new JSONObject();
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        json.put("username","农夫山泉");
        RequestBody body=RequestBody.create(JSON,String.valueOf(json));
        Request request1=new Request.Builder()
                .url(url_cmmon)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response1=client1.newCall(request1).execute();
        String data1=response1.body().string();
        JSONObject object1=(JSONObject)JSONObject.parse(data1);
        fid=object1.getString("username");
        person_name_1.setText(object1.getString("bz"));
        person_username_1.setText(fid);
        person_sign_1.setText(object1.getString("sign"));
        String image_url="src/res/image/"+object1.getString("image");
        person_image.setImage(new Image(new File(image_url).toURI().toString()));
        person_name2_1.setText(object1.getString("remark"));
        person_now_place_1.setText(object1.getString("now_place"));
        person_pre_place_1.setText(object1.getString("pre_place"));
        person_email_1.setText(object1.getString("email"));
        person_xy_1.setText(object1.getString("xy"));
        person_bj_1.setText(object1.getString("bj"));
        person_fdy_1.setText(object1.getString("fdy"));
        person_message_an.setVisible(true);
        bg.setVisible(false);
    }
    @FXML
    private void show_person_message1() throws IOException {
        String url_cmmon="http://127.0.0.1:5000/get_person_message";
        OkHttpClient client1=new OkHttpClient();
        JSONObject json=new JSONObject();
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        json.put("username","lgt153");
        RequestBody body=RequestBody.create(JSON,String.valueOf(json));
        Request request1=new Request.Builder()
                .url(url_cmmon)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response1=client1.newCall(request1).execute();
        String data1=response1.body().string();
        JSONObject object1=(JSONObject)JSONObject.parse(data1);
        fid=object1.getString("username");
        person_name_1.setText(object1.getString("bz"));
        person_username_1.setText(fid);
        person_sign_1.setText(object1.getString("sign"));
        person_name2_1.setText(object1.getString("remark"));
        String image_url="src/res/image/"+object1.getString("image");
        person_image.setImage(new Image(new File(image_url).toURI().toString()));
        person_now_place_1.setText(object1.getString("now_place"));
        person_pre_place_1.setText(object1.getString("pre_place"));
        person_email_1.setText(object1.getString("email"));
        person_xy_1.setText(object1.getString("xy"));
        person_bj_1.setText(object1.getString("bj"));
        person_fdy_1.setText(object1.getString("fdy"));
        person_message_an.setVisible(true);
        bg.setVisible(false);
    }
    @FXML
    private void show_person_message() throws IOException {
        String url_cmmon="http://127.0.0.1:5000/get_person_message";
        OkHttpClient client1=new OkHttpClient();
        JSONObject json=new JSONObject();
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        json.put("username","admin");
        RequestBody body=RequestBody.create(JSON,String.valueOf(json));
        Request request1=new Request.Builder()
                .url(url_cmmon)
                .addHeader("Content-Type", "application/json")
                .post(body)
                .build();
        Response response1=client1.newCall(request1).execute();
        String data1=response1.body().string();
        JSONObject object1=(JSONObject)JSONObject.parse(data1);
        fid=object1.getString("username");
        person_name_1.setText(object1.getString("bz"));
        person_username_1.setText(fid);
        person_sign_1.setText(object1.getString("sign"));
        person_name2_1.setText(object1.getString("remark"));
        String image_url="src/res/image/"+object1.getString("image");
        person_image.setImage(new Image(new File(image_url).toURI().toString()));
        person_now_place_1.setText(object1.getString("now_place"));
        person_pre_place_1.setText(object1.getString("pre_place"));
        person_email_1.setText(object1.getString("email"));
        person_xy_1.setText(object1.getString("xy"));
        person_bj_1.setText(object1.getString("bj"));
        person_fdy_1.setText(object1.getString("fdy"));
        person_message_an.setVisible(true);
        bg.setVisible(false);
    }
    @FXML
    private void  mouse_enter_person1(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#f1f1f1"),null, javafx.geometry.Insets.EMPTY);
        person_pane1.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void mouse_exit_person1(){
        person_pane1.setBackground(null);
    }
    @FXML
    private void  mouse_enter_person11(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#f1f1f1"),null, javafx.geometry.Insets.EMPTY);
        person_pane11.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void mouse_exit_person11(){
        person_pane11.setBackground(null);
    }
    @FXML
    private void  mouse_enter_person111(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#f1f1f1"),null, javafx.geometry.Insets.EMPTY);
        person_pane111.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void mouse_exit_person111(){
        person_pane111.setBackground(null);
    }
    @FXML
    private void  mouse_enter_person1111(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#f1f1f1"),null, javafx.geometry.Insets.EMPTY);
        person_pane1111.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void mouse_exit_person1111(){
        person_pane1111.setBackground(null);
    }
    @FXML
    private void  mouse_enter_person(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#f1f1f1"),null, javafx.geometry.Insets.EMPTY);
        person_pane.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void mouse_exit_person(){
        person_pane.setBackground(null);
    }
    @FXML
    private void person_click(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#F8DA82"),null, javafx.geometry.Insets.EMPTY);
        main_stu_person.setBackground(new Background(backgroundFill));
        Rectangle rectangle=new Rectangle(main_stu_person.prefWidth(-1),main_stu_person.prefHeight(-1));
        rectangle.setArcWidth(16);
        rectangle.setArcHeight(16);
        main_stu_person.setClip(rectangle);
        Rectangle rectangle1=new Rectangle(person_1_image.prefWidth(-1),person_1_image.prefHeight(-1));
        rectangle1.setArcWidth(100);
        rectangle1.setArcHeight(100);
        person_1_image.setClip(rectangle1);

        Rectangle rectangle2=new Rectangle(person_2_image.prefWidth(-1),person_2_image.prefHeight(-1));
        rectangle2.setArcWidth(100);
        rectangle2.setArcHeight(100);
        person_2_image.setClip(rectangle2);

        Rectangle rectangle3=new Rectangle(person_3_image.prefWidth(-1),person_3_image.prefHeight(-1));
        rectangle3.setArcWidth(100);
        rectangle3.setArcHeight(100);
        person_3_image.setClip(rectangle3);

        Rectangle rectangle4=new Rectangle(person_4_image.prefWidth(-1),person_4_image.prefHeight(-1));
        rectangle4.setArcWidth(100);
        rectangle4.setArcHeight(100);
        person_4_image.setClip(rectangle4);

        Rectangle rectangle5=new Rectangle(person_5_image.prefWidth(-1),person_5_image.prefHeight(-1));
        rectangle5.setArcWidth(100);
        rectangle5.setArcHeight(100);
        person_5_image.setClip(rectangle5);
        File file=new File("src/res/fun_image/person_group_end.png");
        String string=file.toURI().toString();
        Image image=new Image(string);
        main_stu_image_person.setImage(image);
        main_stu_label_main.setBackground(null);
        main_stu_image_main.setImage(new Image(new File("src/res/fun_image/main_start.png").toURI().toString()));
        main_stu_label_thing.setBackground(null);
        main_stu_image_thing.setImage(new Image(new File("src/res/fun_image/agenda_start.png").toURI().toString()));
        main_stu_pane.setVisible(false);
        main_stu_title.setVisible(false);
        grade_list.setVisible(false);
        main_stu_person_an.setVisible(true);
        bg.setVisible(true);
    }
    @FXML
    private void more_login_click() throws IOException {
        Stage First_stage=(Stage)main_min.getScene().getWindow();
        Stage stage1=new Stage();
        Parent root1=FXMLLoader.load(getClass().getResource("sample.fxml"));
        stage1.setScene(new Scene(root1));
        stage1.initStyle(StageStyle.UNDECORATED);
        stage1.show();
        First_stage.close();
    }
    @FXML
    private void more_cancle_click(){
        System.exit(0);
    }
    @FXML
    private void more_login_enter(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#f1f1f1"),null, javafx.geometry.Insets.EMPTY);
        main_more_login.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void more_login_exit(){
        main_more_login.setBackground(null);
    }
    @FXML
    private void more_cancle_enter(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#f1f1f1"),null, javafx.geometry.Insets.EMPTY);
        main_more_cancle.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void more_cancle_exit(){
        main_more_cancle.setBackground(null);
    }
    @FXML
    private void unfold(){
        main_more_container.setVisible(true);
    }
    @FXML
    private void more_exit(){
        main_more_container.setVisible(false);
    }
    @FXML
    private void main_min() {
        Stage First_stage=(Stage)main_min.getScene().getWindow();

        First_stage.setIconified(true);
    }
    @FXML
    private void main_cancle(){
        System.exit(0);
    }
    @FXML
    private void main_min_end(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#ABABAB"),null, javafx.geometry.Insets.EMPTY);
        main_min.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void main_min_exit(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#f1f1f1"),null, javafx.geometry.Insets.EMPTY);
        main_min.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void main_cancle_end(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#D41E18"),null, javafx.geometry.Insets.EMPTY);
        main_cancle.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void main_cancle_exit(){
        BackgroundFill backgroundFill=new BackgroundFill(Paint.valueOf("#f1f1f1"),null, Insets.EMPTY);
        main_cancle.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void main_init() throws IOException {
    //        main_chart_cate.setCategories(FXCollections.<String>observableArrayList(Arrays.asList("英语读写","英语听说")));
    //        main_chart_cate.setLabel("科目");
    //        main_chart_num.setLabel("分数");
    //        main_chart_stu.setTitle(name+"的成绩表");

        if(flag==0){
//            Label label=new Label("test");
//            main_cantiner.getChildren().add(label);
            JSONArray jsonArray=JSONArray.parseArray(grade);
            System.out.println(jsonArray);
            for(int i=0;i<jsonArray.size();i++){
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                data.add(new grade_info(jsonObject.getString("kcmc"),jsonObject.getString("teacher"),jsonObject.getString("xf"),jsonObject.getString("grade")));
            }
            JSONObject jsonObject=JSONObject.parseObject(xf_detials);
            xf_average.setText("获得平均学分绩点:"+jsonObject.getString("xf_average"));
            xf_sum.setText("获得学分绩点:"+jsonObject.getString("xf_sum"));
            class_range.setText("班级排名:"+jsonObject.getString("class_range"));
            class_school_range.setText("全校排名:"+jsonObject.getString("class_school_range"));
            kcmc.setCellValueFactory(data->data.getValue().kcmc_Property());
            teacher.setCellValueFactory(data->data.getValue().teacher_Property());
            xf.setCellValueFactory(data->data.getValue().xf_Property());
            cj.setCellValueFactory(data->data.getValue().kscj_Property());
            grade_list.setItems(data);
            xf_progress.setProgress(Double.parseDouble(jsonObject.getString("xf_schedule")));
            String url_cmmon="http://127.0.0.1:5000/get_common";
            OkHttpClient client1=new OkHttpClient();
            JSONObject json=new JSONObject();
            MediaType JSON=MediaType.parse("application/json;charset=utf-8");
            json.put("password","1111");
            RequestBody body=RequestBody.create(JSON,String.valueOf(json));
            Request request1=new Request.Builder()
                    .url(url_cmmon)
                    .addHeader("Content-Type", "application/json")
                    .post(body)
                    .build();
            Response response1=client1.newCall(request1).execute();
            String data1=response1.body().string();
            JSONObject object1=(JSONObject)JSONObject.parse(data1);
            xq=object1.getString("xq");
            System.out.println(xq);
            main_stu_xq.setText(xq);
        }
        flag=1;
    }
    @FXML
    private void login() throws IOException {
        MediaType JSON=MediaType.parse("application/json;charset=utf-8");
        String url="http://127.0.0.1:5000/login";
        OkHttpClient client=new OkHttpClient();
        JSONObject json=new JSONObject();
        String username_content=username.getText();

        String password_content=password.getText();
        json.put("username",username_content);
        json.put("password",password_content);
        if(username_content.equals("")||password_content.equals("")){
            tip.setVisible(true);
        }else{


            String post=json.toString();
            RequestBody body=RequestBody.create(JSON,String.valueOf(json));
            Request request=new Request.Builder()
                    .url(url)
                    .post(body)
                    .addHeader("Content-Type", "application/json")
                    .build();
            Response response=client.newCall(request).execute();
            String data=response.body().string();
            if(data.equals("0")){
                tip.setText("您输入的帐号或密码不正确！");
                tip.setVisible(true);
            }else{

                JSONObject object=(JSONObject)JSONObject.parse(data);
                uid=object.getString("uid");
                user=object.getString("username");
                sex=object.getString("sex");
                place=object.getString("place");
                ctime=object.getString("ctime");
                name=object.getString("name");
                class_list=object.getString("class_list");
                grade=object.getString("grade");
                xf_detials=object.getString("xf_detials");
                fdy=object.getString("fdy");
                System.out.println(fdy);
                System.out.println(grade);
                Stage First_stage=(Stage)Login.getScene().getWindow();
                Stage stage=new Stage();
                Parent root=FXMLLoader.load(getClass().getResource("lodaing.fxml"));
                stage.setScene(new Scene(root));
                stage.initStyle(StageStyle.UNDECORATED);
                stage.setOnShowing(event -> {
                    Label label=(Label)root.lookup("#label_tip");
                    String[] sentence={"正在导入数据.","正在导入数据..","正在导入数据....","正在载入必要插件1/10","正在载入必要插件2/10","正在载入必要插件3/10","正在载入必要插件4/10",
                            "正在载入必要插件5/10","正在载入必要插件6/10","正在载入必要插件7/10","正在载入必要插件8/10","正在载入必要插件9/10","正在载入必要插件10/10","请稍后"};
                    Service<String> service=new Service<String>() {
                        @Override
                        protected Task<String> createTask() {
                            return new Task<String>() {
                                @Override
                                protected String call() throws Exception {
                                    int i=0;
                                    for(;i<5;i++){
                                        updateValue(sentence[i]);

                                        Thread.sleep(500);
                                    }
                                    for(;i<13;i++){
                                        updateValue(sentence[i]);
                                        Thread.sleep(100);
                                    }
                                    for(int j=0;j<=38;j++){
                                        updateValue(sentence[i]+j+"%");
                                        Thread.sleep(100);
                                    }
                                    for(int j=39;j<=60;j++){
                                        updateValue(sentence[i]+j+"%");
                                        Thread.sleep(250);
                                    }
                                    for(int j=61;j<=88;j++){
                                        updateValue(sentence[i]+j+"%");
                                        Thread.sleep(100);
                                    }
                                    for(int j=88;j<=100;j++){
                                        updateValue(sentence[i]+j+"%");
                                        Thread.sleep(300);
                                    }
                                    return "Success";
                                }
                            };
                        }
                    };
                    label.textProperty().bind(service.valueProperty());
                    service.setOnSucceeded((WorkerStateEvent event1)->{
                        stage.close();
                        try {
                            Rectangle2D screenRectangle= Screen.getPrimary().getBounds();
                            double width=screenRectangle.getWidth();
                            double height=screenRectangle.getHeight();
                            System.out.println(width+" "+height);
                            Thread.sleep(500);

                            Stage stage1=new Stage();
                            Parent root1=FXMLLoader.load(getClass().getResource("main.fxml"));
                            stage1.setScene(new Scene(root1));
                            stage1.initStyle(StageStyle.UNDECORATED);
                            Stage stage_se=new Stage();
                            Parent root_se=FXMLLoader.load(getClass().getResource("greeting.fxml"));
                            stage_se.setScene(new Scene(root_se));
                            stage_se.initStyle(StageStyle.UNDECORATED);
                            stage_se.setX(width-320);
                            stage_se.setY(height-370);
                            stage1.setOnShowing(event2 -> {
                                ImageView image_user=(ImageView)root1.lookup("#main_user");
                                Label label1_username=(Label)root1.lookup("#main_username");
                                Label label1_place=(Label)root1.lookup("#main_place");
                                Rectangle rectangle=new Rectangle(image_user.prefWidth(-1),image_user.prefHeight(-1));
                                rectangle.setArcWidth(100);
                                rectangle.setArcHeight(100);
                                image_user.setClip(rectangle);
                                label1_username.setText(user);
                                if(place.compareTo("0.0")==0)
                                    label1_place.setText("同学");
                                else
                                    label1_place.setText("老师");

                            });
                            stage1.show();
                            stage_se.setOnShowing(event2 -> {
                                Label label1=(Label) root_se.lookup("#greeting_user");
                                Label label2=(Label)root_se.lookup("#greeting_content");
                                ImageView gr_image=(ImageView)root_se.lookup("#greeting_image");
                                Random r=new Random();
                                int ran1=r.nextInt(8);
                                String image_url="src/res/greeting/"+Integer.toString(ran1)+".jpg";
                                System.out.println(image_url);
                                gr_image.setImage(new Image(new File(image_url).toURI().toString()));
                                if(place.compareTo("0.0")==0)
                                    label1.setText("Hi,"+name+"同学,你好");
                                else
                                    label2.setText("Hi,"+name.charAt(0)+"老师,您好");
                                label2.setText("新的一天要一直开心！");
                            });
                            System.out.println(stage_se.getY());
                            stage_se.show();



                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    });
                    service.start();
                    First_stage.close();

                });
                stage.show();
            }
        }

    }
    @FXML
    private void greeting_cang(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#D41E18"),null, javafx.geometry.Insets.EMPTY);
        greeting_cancle.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void greeting_cancle_exit(){
        greeting_cancle.setBackground(null);
    }
    @FXML
    private void greeting_close(){
        Stage First_stage=(Stage)greeting_cancle.getScene().getWindow();
        First_stage.close();
    }
    @FXML
    private void cancle(){
        BackgroundFill backgroundFill=new BackgroundFill(javafx.scene.paint.Paint.valueOf("#D41E18"),null, javafx.geometry.Insets.EMPTY);
        label_cancle.setBackground(new Background(backgroundFill));
    }
    @FXML
    private void exit(){
        BackgroundFill backgroundFill=new BackgroundFill(Paint.valueOf("#20C0B8"),null, Insets.EMPTY);
        label_cancle.setBackground(new Background(backgroundFill));
    }
    @FXML
    private  void min_end(){
        File file=new File("src/res/image/min_end.png");
        String string=file.toURI().toString();
        Image image=new Image(string);
        min.setImage(image);

    }
    @FXML
    private  void min_start(){
        File file=new File("src/res/image/min_start.png");
        String string=file.toURI().toString();
        Image image=new Image(string);
        min.setImage(image);
    }

    @FXML
    private void cancle_end(){
        File file=new File("src/res/image/cancle_end.png");
        String string =file.toURI().toString();
        Image image=new Image(string);
        cancle.setImage(image);


    }
    @FXML
    private void min(){
        
    }
    @FXML
    private void cancle_start(){
        File file=new File("src/res/image/cancle_start.png");
        String string=file.toURI().toString();
        Image image=new Image(string);
        cancle.setImage(image);
    }
    @FXML
    private void Change_tip() throws IOException {
//        System.out.println(uid+" "+user+" "+sex+" "+place+" "+ctime+" "+name);
//
//        int count=0;
//        String[] sentence={"正在导入数据.","正在导入数据..","正在导入数据....","正在载入必要插件1/10","正在载入必要插件2/10","正在载入必要插件3/10","正在载入必要插件4/10",
//                "正在载入必要插件5/10","正在载入必要插件6/10","正在载入必要插件7/10","正在载入必要插件8/10","正在载入必要插件9/10","正在载入必要插件10/10","请稍后"};
//        if(flag==1){
//            Service<String> service=new Service<String>() {
//                @Override
//                protected Task<String> createTask() {
//                    return new Task<String>() {
//                        @Override
//                        protected String call() throws Exception {
//                            int i=0;
//                            for(;i<5;i++){
//                                updateValue(sentence[i]);
//
//                                Thread.sleep(500);
//                            }
//                            for(;i<13;i++){
//                                updateValue(sentence[i]);
//                                Thread.sleep(100);
//                            }
//                            for(int j=0;j<=38;j++){
//                                updateValue(sentence[i]+j+"%");
//                                Thread.sleep(100);
//                            }
//                            for(int j=39;j<=60;j++){
//                                updateValue(sentence[i]+j+"%");
//                                Thread.sleep(250);
//                            }
//                            for(int j=61;j<=88;j++){
//                                updateValue(sentence[i]+j+"%");
//                                Thread.sleep(100);
//                            }
//                            for(int j=88;j<=100;j++){
//                                updateValue(sentence[i]+j+"%");
//                                Thread.sleep(300);
//                            }
//                            return "Success";
//                        }
//                    };
//                }
//            };
//            label_tip.textProperty().bind(service.valueProperty());
//            service.setOnSucceeded((WorkerStateEvent event)->{
//                try {
//                    Rectangle2D screenRectangle= Screen.getPrimary().getBounds();
//                    double width=screenRectangle.getWidth();
//                    double height=screenRectangle.getHeight();
//                    System.out.println(width+" "+height);
//                    Thread.sleep(500);
//                    Stage First_stage=(Stage)label_tip.getScene().getWindow();
//                    Stage stage=new Stage();
//                    Parent root=FXMLLoader.load(getClass().getResource("main.fxml"));
//                    stage.setScene(new Scene(root));
//                    stage.initStyle(StageStyle.UNDECORATED);
//                    stage.show();
//                    Stage stage_se=new Stage();
//                    Parent root_se=FXMLLoader.load(getClass().getResource("greeting.fxml"));
//                    stage_se.setScene(new Scene(root_se));
//                    stage_se.initStyle(StageStyle.UNDECORATED);
//                    stage_se.setX(width-400);
//                    stage_se.setY(height-370);
//                    stage_se.show();
//                    First_stage.close();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            });
//            service.start();
//        }
    }
    @FXML
    private void cancle_label(){
        System.exit(0);
    }

    public class grade_info{
        private StringProperty grade_kcmc;
        private StringProperty grade_teacher;
        private StringProperty grade_xf;
        private StringProperty grade_kscj;
        public grade_info(String grade_kcmc,String grade_teacher,String grade_xf,String grade_kscj){
            super();
            this.grade_kcmc=new SimpleStringProperty(grade_kcmc);
            this.grade_kscj=new SimpleStringProperty(grade_kscj);
            this.grade_teacher=new SimpleStringProperty(grade_teacher);
            this.grade_xf=new SimpleStringProperty(grade_xf);
        }
        public String get_kcmc(){
            return grade_kcmc.get();
        }
        public void setGrade_kcmc(String grade_kcmc){
            this.grade_kcmc.set(grade_kcmc);
        }
        public StringProperty kcmc_Property(){
            return grade_kcmc;
        }
        public String get_teacher(){
            return grade_teacher.get();
        }
        public void setGrade_teacher(String grade_teacher){
            this.grade_teacher.set(grade_teacher);
        }
        public StringProperty teacher_Property(){
            return grade_teacher;
        }
        public String get_xf(){
            return grade_xf.get();
        }
        public void setGrade_xf(String grade_xf){
            this.grade_xf.set(grade_xf);
        }
        public StringProperty xf_Property(){
            return grade_xf;
        }
        public String get_kscj(){
            return grade_kscj.get();
        }
        public void setGrade_kscj(String grade_kscj){
            this.grade_kscj.set(grade_kscj);
        }
        public StringProperty kscj_Property(){
            return grade_kscj;
        }
    }
}
